package edu.neu.javaweb.controller;

import edu.neu.javaweb.service.EmployeeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "EmpDeleteServlet", urlPatterns = {"/pages/emp_delete"})
public class EmpDeleteServlet extends HttpServlet {
    Logger log = LoggerFactory.getLogger(this.getClass().getName());

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        int id = Integer.parseInt(request.getParameter("id"));

        log.info("删除emp id:" + id);

        new EmployeeService().deleteById(id);
        response.sendRedirect("emp_list");
//        request.getRequestDispatcher("emp_list.jsp").forward(request,response);
    }
}
